package com.zhaojk.audio.mapper;

import com.zhaojk.audio.entity.PromptTemplate;
import com.zhaojk.audio.mapper.handler.PgJsonbTypeHandler;
import org.apache.ibatis.annotations.*;
import java.util.List;

/**
 * @author zhaojk
 */
@Mapper
public interface PromptTemplateMapper {
    @Insert("INSERT INTO prompt_template(name, description, template_content, category, style, variables) " +
            "VALUES(#{name}, #{description}, #{templateContent}, #{category}, #{style}, " +
            "#{variables, typeHandler=com.zhaojk.audio.mapper.handler.PgJsonbTypeHandler})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(PromptTemplate template);

    @Select("SELECT * FROM prompt_template WHERE id = #{id}")
    @Results({
            @Result(property = "templateContent", column = "template_content"),
            @Result(property = "isActive", column = "is_active"),
            @Result(property = "createdAt", column = "created_at"),
            @Result(property = "updatedAt", column = "updated_at"),
            @Result(property = "variables", column = "variables",
                    typeHandler = PgJsonbTypeHandler.class)
    })
    PromptTemplate findById(Integer id);

    @Select("SELECT * FROM prompt_template WHERE is_active = true")
    @Results({
            @Result(property = "templateContent", column = "template_content"),
            @Result(property = "isActive", column = "is_active"),
            @Result(property = "createdAt", column = "created_at"),
            @Result(property = "updatedAt", column = "updated_at"),
            @Result(property = "variables", column = "variables",
                    typeHandler = PgJsonbTypeHandler.class)
    })
    List<PromptTemplate> findAllActive();
}
